﻿using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using XYAC.Framework.MonitorTireMaterialOnline.Extensions;
using XYAC.Framework.MonitorTireMaterialOnline.ViewModels;
using XYAC.Framework.MonitorTireMaterialOnline.Views;

namespace XYAC.Framework.MonitorTireMaterialOnline
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow(IOptionsMonitor<AppConfig> options, ILogger<MainWindow> logger, MainWindowViewModel viewmodel, SystemConfigView systemConfigView, QualityDataHistoryView qualityDataHistoryView/*, SemiSteelTreadScanView semiSteelTreadScanView*/)
        {

            InitializeComponent();

            this.DataContext = viewmodel;
            (this.MainTab.Items[0] as TabItem).Content = qualityDataHistoryView;
            (this.MainTab.Items[1] as TabItem).Content = systemConfigView;
            var workingArea = SystemParameters.WorkArea;
            this.Width = workingArea.Width;
            this.Height = workingArea.Height;

            this.Closing += MainWindow_Closing;
        }

        private void MainWindow_Closing(object? sender, CancelEventArgs e)
        {
            this.Hide();
            e.Cancel = true;
        }


        private void MainTab_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if ((this.MainTab.Items[0] as TabItem).Content is QualityDataHistoryView view && view.DataContext is QualityDataHistoryViewModel vm)
            {
                vm.QueryLocalDataHistory();
            }
        }
    }
}